rep<-100;
minSize<-5
maxSize<-15

reset<-function(){
	print("purging workspace")
	rm(list=ls())
	source("specyfikacja.r")
	source("sort.r")
	source("best_first.R");
}
reset()
matDimension<-vector();
avgExecutionTime<-vector();
avgTraceLength<-vector();
avgTraceClosedLength<-vector();
pdf()

ctitle<-function(x,y,pSize){
	return (paste(y,"(",x,")"));
}
csubtitle<-function(tries){
	return (paste("wyniki srednie dla",tries,"iteracji."));
}

for(k in minSize:maxSize){
	traceClosedLength<-vector();	
	traceLength<-vector();
	executionTime<-vector();

	for(i in 1:rep){
		print(paste("dimension: ",as.character(k),", iteration: ",as.character(i)));
		sort.task<-genSequence(k);
		time<-system.time(bf.search("sort"));
		traceLength[length(traceLength)+1]<-length(trace);
		traceClosedLength[length(traceClosedLength)+1]<-length(trace[!open]);
		executionTime[length(executionTime)+1]<-time[3];	
		reset();
	}
	plot(traceLength,executionTime,main=ctitle("dlugosc sladu","czas wykonania"),sub=paste("rozmiar problemu:",k));
	plot(traceClosedLength,executionTime,main=ctitle("liczba wybranych elementow sladu","czas wykonania"),sub=paste("rozmiar problemu:",k));
	matDimension[length(matDimension)+1]<-k;
	avgExecutionTime[length(avgExecutionTime)+1]<-ave(executionTime)[1];
	avgTraceLength[length(avgTraceLength)+1]<-ave(traceLength)[1];
	avgTraceClosedLength[length(avgTraceClosedLength)+1]<-ave(traceClosedLength)[1];
}
plot(matDimension,avgExecutionTime,main=ctitle("rozmiar problemu","czas wykonania"),sub=csubtitle((maxSize+1-minSize)))
plot(matDimension,avgTraceLength,main=ctitle("rozmiar problemu","dlugosc sladu"),sub=csubtitle((maxSize+1-minSize)))
plot(matDimension,avgTraceClosedLength,main=ctitle("rozmiar problemu","dlugosc sladu"),sub=csubtitle((maxSize+1-minSize)))
plot(avgTraceLength,avgExecutionTime,main=ctitle("srednia dlugosc sladu","sredni czas wykonania"),sub=csubtitle((maxSize+1-minSize)))
plot(avgTraceClosedLength,avgExecutionTime,main=ctitle("srednia liczba wybranych punktow sladu","sredni czas wykonania"),sub=csubtitle((maxSize+1-minSize)))
plot(avgTraceClosedLength,avgTraceLength,main=ctitle("srednia liczba wybranych punktow sladu","srednia dlugosc sladu"),sub=csubtitle((maxSize+1-minSize)))
dev.off()
reset()
